home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / pibt40s1.arc / GETOTHER.MOD < prev    next >
Encoding:
Text File  |  1987-03-26  |  18.0 KB  |  482 lines

  1. (*----------------------------------------------------------------------*)
  2. (*                Get_Other_Files --- read initialization files         *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. PROCEDURE Get_Other_Files;
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*     Procedure: Get_Other_Files                                       *)
  10. (*                                                                      *)
  11. (*     Purpose:   Reads other initialization files than primary config. *)
  12. (*                file PIBTERM.CNF.                                     *)
  13. (*                                                                      *)
  14. (*     Calling Sequence:                                                *)
  15. (*                                                                      *)
  16. (*        Get_Other_Files;                                              *)
  17. (*                                                                      *)
  18. (*     Calls:                                                           *)
  19. (*                                                                      *)
  20. (*----------------------------------------------------------------------*)
  21.  
  22. VAR
  23.    I                    : INTEGER;
  24.  
  25. (*----------------------------------------------------------------------*)
  26. (*            Read_Prefix_File --- Read dialing prefix file             *)
  27. (*----------------------------------------------------------------------*)
  28.  
  29. PROCEDURE Read_Prefix_File;
  30.  
  31. (*----------------------------------------------------------------------*)
  32. (*                                                                      *)
  33. (*     Procedure:  Read_Prefix_File                                     *)
  34. (*                                                                      *)
  35. (*     Purpose:    Reads dialing prefix file                            *)
  36. (*                                                                      *)
  37. (*     Calling Sequence:                                                *)
  38. (*                                                                      *)
  39. (*        Read_Prefix_File;                                             *)
  40. (*                                                                      *)
  41. (*      Calls:   Read_Config_File                                       *)
  42. (*               Read_Prefix_File                                       *)
  43. (*               Read_Phone_Directory                                   *)
  44. (*                                                                      *)
  45. (*----------------------------------------------------------------------*)
  46.  
  47. VAR
  48.    Iprefix           : INTEGER;
  49.    OK_To_Read        : BOOLEAN;
  50.    Full_Name         : AnyStr;
  51.    Phone_Prefix_File : Text_File;
  52.  
  53. BEGIN (* Read_Prefix_File *)
  54.                                    (* Clear out prefix entries *)
  55.  
  56.    FOR Iprefix := 1 TO Max_Phone_Prefixes DO
  57.       Phone_Prefix_Nos[Iprefix] := '';
  58.  
  59.                                    (* Assign phone prefix file *)
  60.  
  61.    IF ( POS( '\' , Prefix_File_Name ) = 0 ) AND
  62.       ( POS( ':' , Prefix_File_Name ) = 0 ) THEN
  63.       Full_Name := Home_Dir + Prefix_File_Name
  64.    ELSE
  65.       Full_Name := Prefix_File_Name;
  66.  
  67.    ASSIGN( Phone_Prefix_File , Full_Name );
  68.         (*$I-*)
  69.    RESET( Phone_Prefix_File );
  70.         (*$I+*)
  71.  
  72.    OK_To_Read := ( Int24Result = 0 );
  73.    TextColor( WHITE );
  74.  
  75.    IF NOT OK_To_Read THEN
  76.       WRITELN('Can''t find prefix file ',Full_Name,', no prefixes set.')
  77.  
  78.                                    (* Read prefix entries *)
  79.    ELSE
  80.       BEGIN
  81.  
  82.          WRITELN('Reading phone prefixes from ',Full_Name);
  83.  
  84.          Iprefix := 1;
  85.  
  86.          REPEAT
  87.             READLN( Phone_Prefix_File , Phone_Prefix_Nos[ Iprefix ] );
  88.             Phone_Prefix_Nos[ Iprefix ] :=
  89.                Read_Ctrls( Phone_Prefix_Nos[ Iprefix ] );
  90.             Iprefix := Iprefix + 1;
  91.          UNTIL( EOF( Phone_Prefix_File ) OR ( Iprefix > Max_Phone_Prefixes ) );
  92.  
  93.               (*$I-*)
  94.          CLOSE( Phone_Prefix_File );
  95.               (*$I+*)
  96.  
  97.       END;
  98.                                    (* Write new prefix file *)
  99.  
  100.    IF NOT Ok_To_Read THEN
  101.       BEGIN
  102.  
  103.          ASSIGN( Phone_Prefix_File , Full_Name );
  104.              (*$I-*)
  105.          REWRITE( Phone_Prefix_File );
  106.              (*$I+*)
  107.  
  108.          IF Int24Result <> 0 THEN
  109.             BEGIN
  110.                WRITELN;
  111.                WRITELN('Can''t create new dialing prefix file ',Full_Name,'.')
  112.             END
  113.          ELSE
  114.             BEGIN
  115.  
  116.                WRITELN;
  117.                WRITELN('Creating dialing prefix file ',Full_Name,'.');
  118.  
  119.                FOR Iprefix := 1 TO Max_Phone_Prefixes DO
  120.                   WRITELN( Phone_Prefix_File , Phone_Prefix_Nos[ Iprefix ] );
  121.  
  122.                CLOSE( Phone_Prefix_File );
  123.  
  124.             END;
  125.  
  126.       END;
  127.  
  128. END   (* Read_Prefix_File *);
  129.  
  130. (*----------------------------------------------------------------------*)
  131. (*        Read_Phone_Directory --- Read phone number directory          *)
  132. (*----------------------------------------------------------------------*)
  133.  
  134. PROCEDURE Read_Phone_Directory;
  135.  
  136. (*----------------------------------------------------------------------*)
  137. (*                                                                      *)
  138. (*     Procedure:  Read_Phone_Directory                                 *)
  139. (*                                                                      *)
  140. (*     Purpose:    Read phone directory entries                         *)
  141. (*                                                                      *)
  142. (*     Calling Sequence:                                                *)
  143. (*                                                                      *)
  144. (*        Read_Phone_Directory;                                         *)
  145. (*                                                                      *)
  146. (*      Calls:   Read_Config_File                                       *)
  147. (*               Read_Prefix_File                                       *)
  148. (*                                                                      *)
  149. (*      Remarks:                                                        *)
  150. (*                                                                      *)
  151. (*          Watch out -- some tricky stuff with accessing string data   *)
  152. (*          and lengths is used here.                                   *)
  153. (*                                                                      *)
  154. (*----------------------------------------------------------------------*)
  155.  
  156. VAR
  157.    I          : INTEGER;
  158.    J          : INTEGER;
  159.    L          : INTEGER;
  160.    OK_To_Read : BOOLEAN;
  161.    T_String   : AnyStr;
  162.    Phone_File : TEXT[4096];
  163.    Phone_Str  : AnyStr;
  164.    Full_Name  : AnyStr;
  165.  
  166. BEGIN (* Read_Phone_Directory *)
  167.                                    (* Indicate we're reading phone numbers *)
  168.  
  169.    IF ( POS( '\' , Dialing_File_Name ) = 0 ) AND
  170.       ( POS( ':' , Dialing_File_Name ) = 0 ) THEN
  171.       Full_Name := Home_Dir + Dialing_File_Name
  172.    ELSE
  173.       Full_Name := Dialing_File_Name;
  174.  
  175.    WRITELN('Reading dialing directory ',Full_Name);
  176.  
  177.                                    (* Assign phone number file *)
  178.  
  179.    ASSIGN( Phone_File , Full_Name );
  180.         (*$I-*)
  181.    RESET( Phone_File );
  182.         (*$I+*)
  183.  
  184.    OK_To_Read := ( INT24Result = 0 );
  185.    TextColor( WHITE );
  186.                                    (* Create phone directory if needed *)
  187.  
  188.    IF ( NOT OK_To_Read ) THEN
  189.       BEGIN  (* Phone directory doesn't exist *)
  190.  
  191.          ASSIGN( Phone_File , Full_Name );
  192.              (*$I-*)
  193.          REWRITE( Phone_File );
  194.              (*$I+*)
  195.  
  196.          IF Int24Result <> 0 THEN
  197.             BEGIN
  198.                WRITELN;
  199.                WRITELN('Can''t create new phone directory ',Full_Name,'.')
  200.             END
  201.          ELSE
  202.             BEGIN  (* Create phone directory *)
  203.  
  204.                WRITELN;
  205.                WRITELN('Creating phone directory ',Full_Name,'.');
  206.  
  207.                WITH Phone_Entry_Data DO
  208.                   BEGIN
  209.  
  210.                      CopyStoA( Dupl( '-' , 25 ) , Phone_Name ,   25 );
  211.                      CopyStoA( ' # ### ###-####' , Phone_Number , 15 );
  212.  
  213.                      Phone_Parity   := COPY( Parity, 1, 1 );
  214.  
  215.                      STR ( Baud_Rate:5 , T_String );
  216.                      CopyStoA( T_String , Phone_Baud , 5 );
  217.  
  218.                      STR ( Data_Bits:1 , T_String );
  219.                      Phone_Databits := T_STRING[1];
  220.  
  221.                      STR ( Stop_Bits:1 , T_String );
  222.                      Phone_StopBits := T_STRING[1];
  223.  
  224.                      IF Local_Echo THEN
  225.                         Phone_Echo := 'Y'
  226.                      ELSE
  227.                         Phone_Echo := 'N';
  228.  
  229.                      IF ( BS_Char = CHR( BS ) ) THEN
  230.                         Phone_BackSpace := 'B'
  231.                      ELSE
  232.                         Phone_BackSpace := 'D';
  233.  
  234.                      IF Add_LF THEN
  235.                         Phone_LineFeed := 'Y'
  236.                      ELSE
  237.                         Phone_LineFeed := 'N';
  238.  
  239.                      Phone_Term_Type   := COPY( Dec_To_Hex( ORD( Terminal_to_Emulate ) ), 1, 1 );
  240.  
  241.                      Phone_Trans_Type  := Trans_Type_Name[ Default_Transfer_Type ];
  242.  
  243.                      Phone_Script      := '         ';
  244.  
  245.                      Phone_Last_Date   := '        ';
  246.  
  247.                      Phone_Last_Time   := '        ';
  248.  
  249.                   END;
  250.  
  251.                Phone_Str[0] := CHR( Dialing_Dir_Entry_Length );
  252.                MOVE( Phone_Entry_Data, Phone_Str[1],
  253.                      Dialing_Dir_Entry_Length );
  254.  
  255.                FOR I := 1 TO Dialing_Dir_Size_Max DO
  256.                   BEGIN
  257.                     Dialing_Directory^[I] := Phone_Entry_Data;
  258.                     WRITELN( Phone_File , Phone_Str );
  259.                   END;
  260.  
  261.                CLOSE( Phone_File );
  262.  
  263.                Dialing_Dir_Size := Dialing_Dir_Size_Max;
  264.  
  265.                EXIT;
  266.  
  267.             END    (* Create phone directory *);
  268.  
  269.       END   (* Phone directory doesn't exist *);
  270.  
  271.                                    (* Finally, read in directory! *)
  272.       (*$I-*)
  273.  
  274.    Dialing_Dir_Size := 0;
  275.  
  276.    REPEAT
  277.  
  278.       READLN( Phone_File, Phone_Str );
  279.  
  280.       L := LENGTH( Phone_Str );
  281.       FOR J := ( L + 1 ) TO Dialing_Dir_Entry_Length DO
  282.          Phone_Str[J] := ' ';
  283.  
  284.       MOVE( Phone_Str[1], Phone_Entry_Data, Dialing_Dir_Entry_Length );
  285.  
  286.       Dialing_Dir_Size                     := Dialing_Dir_Size + 1;
  287.       Dialing_Directory^[Dialing_Dir_Size] := Phone_Entry_Data;
  288.  
  289.    UNTIL( EOF( Phone_File ) OR ( Dialing_Dir_Size >= Dialing_Dir_Size_Max ) );
  290.  
  291.    CLOSE( Phone_File );
  292.       (*$I+*)
  293.  
  294.    I := INT24Result;
  295.  
  296. END   (* Read_Phone_Directory *);
  297.  
  298. (*----------------------------------------------------------------------*)
  299. (*        Read_Function_Keys --- Read function key definitions          *)
  300. (*----------------------------------------------------------------------*)
  301.  
  302. PROCEDURE Read_Function_Keys;
  303.  
  304. (*----------------------------------------------------------------------*)
  305. (*                                                                      *)
  306. (*     Procedure:  Read_Function_Keys                                   *)
  307. (*                                                                      *)
  308. (*     Purpose:    Read function key definitions                        *)
  309. (*                                                                      *)
  310. (*     Calling Sequence:                                                *)
  311. (*                                                                      *)
  312. (*        Read_Function_Keys;                                           *)
  313. (*                                                                      *)
  314. (*      Calls:   Read_Config_File                                       *)
  315. (*               Read_Prefix_File                                       *)
  316. (*               Read_Phone_Directory                                   *)
  317. (*                                                                      *)
  318. (*----------------------------------------------------------------------*)
  319.  
  320. VAR
  321.    Input_Key_File : Text;
  322.    Key_Name       : STRING[3];
  323.    Key_Text       : AnyStr;
  324.    Section_No     : INTEGER;
  325.    Key_Def_Text   : AnyStr;
  326.    Key_Number     : INTEGER;
  327.    L_Text         : INTEGER;
  328.    I              : INTEGER;
  329.    J              : INTEGER;
  330.    Full_Name      : AnyStr;
  331.  
  332. (*----------------------------------------------------------------------*)
  333. (*       Process_Key_Definition --- Process Function Key Definition     *)
  334. (*----------------------------------------------------------------------*)
  335.  
  336. PROCEDURE Process_Key_Definition;
  337.  
  338. (*----------------------------------------------------------------------*)
  339. (*                                                                      *)
  340. (*     Procedure:  Process_Key_Definition                               *)
  341. (*                                                                      *)
  342. (*     Purpose:    Process and store key definition string              *)
  343. (*                                                                      *)
  344. (*     Calling Sequence:                                                *)
  345. (*                                                                      *)
  346. (*        Process_Key_Definition;                                       *)
  347. (*                                                                      *)
  348. (*           On entry, Key_Text should have the key definition text     *)
  349. (*           as read from a file.                                       *)
  350. (*                                                                      *)
  351. (*----------------------------------------------------------------------*)
  352.  
  353. BEGIN (* Process_Key_Definition *)
  354.  
  355.                                    (* Get key name   *)
  356.  
  357.    I        := POS( '=' , Key_Text );
  358.    L_Text   := LENGTH( Key_Text );
  359.  
  360.    IF ( I > 0 ) THEN
  361.       Define_Key( Substr( Key_Text, 1, I - 1 ) ,
  362.                   Substr( Key_Text, I + 1 , L_Text - I ) );
  363.  
  364. END   (* Process_Key_Definition *);
  365.  
  366. (*----------------------------------------------------------------------*)
  367.  
  368. BEGIN (* Read_Function_Keys *)
  369.                                    (* Attach file with definitions *)
  370.  
  371.    IF ( POS( '\' , Function_Key_Name ) = 0 ) AND
  372.       ( POS( ':' , Function_Key_Name ) = 0 ) THEN
  373.       Full_Name := Home_Dir + Function_Key_Name
  374.    ELSE
  375.       Full_Name := Function_Key_Name;
  376.  
  377.    ASSIGN( Input_Key_File , Full_Name );
  378.        (*$I-*)
  379.    RESET ( Input_Key_File );
  380.        (*$I+*)
  381.                                    (* See if openable *)
  382.    IF ( Int24Result = 0 ) THEN
  383.       BEGIN (* File OK, read definitions *)
  384.  
  385.          WRITELN('Reading key definitions from ',Full_Name);
  386.  
  387.          REPEAT
  388.  
  389.             Key_Text       := ' ';
  390.                                    (* Read key definition *)
  391.  
  392.             READLN( Input_Key_File , Key_Text );
  393.  
  394.                                    (* Process it *)
  395.  
  396.             Process_Key_Definition;
  397.  
  398.          UNTIL( EOF( Input_Key_File ) );
  399.  
  400.          CLOSE( Input_Key_File );
  401.  
  402.       END   (* File OK, read definitions *);
  403.  
  404. END   (* Read_Function_Keys *);
  405.  
  406. (*----------------------------------------------------------------------*)
  407. (*        Read_Translate_Table --- Read translate table definitions     *)
  408. (*----------------------------------------------------------------------*)
  409.  
  410. PROCEDURE Read_Translate_Table;
  411.  
  412. (*----------------------------------------------------------------------*)
  413. (*                                                                      *)
  414. (*     Procedure:  Read_Translate_Table                                 *)
  415. (*                                                                      *)
  416. (*     Purpose:    Read translate table definitions                     *)
  417. (*                                                                      *)
  418. (*     Calling Sequence:                                                *)
  419. (*                                                                      *)
  420. (*        Read_Translate_Table;                                         *)
  421. (*                                                                      *)
  422. (*      Calls:   Read_Config_File                                       *)
  423. (*               Read_Prefix_File                                       *)
  424. (*               Read_Phone_Directory                                   *)
  425. (*                                                                      *)
  426. (*----------------------------------------------------------------------*)
  427.  
  428. VAR
  429.    TrTab_File : TEXT;
  430.    I          : INTEGER;
  431.    J          : INTEGER;
  432.    Full_Name  : AnyStr;
  433.  
  434. BEGIN (* Read_Translate_Table *)
  435.  
  436.    IF ( POS( '\' , Translate_File_Name ) = 0 ) AND
  437.       ( POS( ':' , Translate_File_Name ) = 0 ) THEN
  438.       Full_Name := Home_Dir + Translate_File_Name
  439.    ELSE
  440.       Full_Name := Translate_File_Name;
  441.  
  442.    ASSIGN( TrTab_File , Full_Name );
  443.       (*$I-*)
  444.    RESET ( TrTab_File );
  445.       (*$I+*)
  446.  
  447.    IF ( Int24Result = 0 ) THEN
  448.       BEGIN (* File OK, read definition *)
  449.  
  450.          WRITELN('Reading translate table from ', Full_Name);
  451.  
  452.          REPEAT
  453.                (*$I-*)
  454.             READLN( TrTab_File , I, J );
  455.                (*$I+*)
  456.             IF Int24Result = 0 THEN
  457.                IF ( I >= 0 ) AND ( I <= 255 ) AND
  458.                   ( J >= 0 ) AND ( J <= 255 ) THEN
  459.                   TrTab[CHR(I)] := CHR( J );
  460.  
  461.          UNTIL( EOF( TrTab_File ) );
  462.  
  463.       END   (* Get definition from file *);
  464.  
  465.    CLOSE( TrTab_File );
  466.  
  467. END   (* Read_Translate_Table *);
  468.  
  469. (*----------------------------------------------------------------------*)
  470.  
  471. BEGIN (* Get_Other_Files *)
  472.                                    (* Read dialing prefix file        *)
  473.    Read_Prefix_File;
  474.                                    (* Read dialing entries            *)
  475.    Read_Phone_Directory;
  476.                                    (* Read function key definitions   *)
  477.    Read_Function_Keys;
  478.                                    (* Read translate table definitions*)
  479.    Read_Translate_Table;
  480.  
  481. END   (* Get_Other_Files *);
  482.